package com.itboye.ihomebank.myzhujia;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ConfigBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.login.LoginActivity;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

/**
 * 选择保修类型
 * 
 */
public class ActivityRepair extends BaseOtherActivity implements Observer {
	TextView add_shap_title_tv;
	ImageView close_icon;
	LinearLayout repair_jinji, repair_jvjia, repair_jiadian;
	UserPresenter userPresenter;
	private String phone;

	@Override
	protected int layout_id() {
		return R.layout.activity_repair;
	}

	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {
		case R.id.close_icon:// 返回
			finish();
			break;
		case R.id.repair_jinji:// 紧急维修
			if (phone != null) {
				intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
						+ phone));
				startActivity(intent);
			} else {
				ByAlert.alert("暂未获取到客服信息");
			}
			// intent = new
			// Intent(ActivityRepair.this,ActivityRepairAppointment.class);
			// startActivity(intent);
			break;
		case R.id.repair_jvjia:// 居家维修
			if (SPUtils.get(this, null, SPContants.USER_ID, "").equals("")) {
				startActivity(new Intent(this, LoginActivity.class));
			} else {
				intent = new Intent(ActivityRepair.this,
						ActivityHomeRepair.class);
				intent.putExtra("title", "居家维修");
				startActivity(intent);
			}
			break;
		case R.id.repair_jiadian:// 家电维修
			if (SPUtils.get(this, null, SPContants.USER_ID, "").equals("")) {
				startActivity(new Intent(this, LoginActivity.class));
			} else {
				intent = new Intent(ActivityRepair.this,
						ActivityHomeRepair.class);
				intent.putExtra("title", "家电维修");
				startActivity(intent);
			}
			break;

		default:
			break;
		}
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		add_shap_title_tv.setText("选择保修类型");
		userPresenter = new UserPresenter(this);
		userPresenter.getConfig();
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == UserPresenter.getConfig_success) {
				ConfigBean configBean = (ConfigBean) entity.getData();
				phone = configBean.getCustomerPhone().get(0).getValue();
			} else if (entity.getEventType() == UserPresenter.getConfig_fail) {

			}
		}
	}

}
